//
//  ThemeManager.m
//  LingQian
//
//  Created by xieyingze on 2018/1/21.
//  Copyright © 2018年 xieyingze. All rights reserved.
//

#import "ThemeManager.h"
#import "ColorDefine.h"
#import "UserInfoDefine.h"

@interface ThemeManager()

@end

@implementation ThemeManager

+ (instancetype)shareInstance {
    static dispatch_once_t once;
    static id _instance;
    dispatch_once(&once, ^{
        _instance = [[self alloc] init];
    });
    return  _instance;
}

#pragma mark - Interface

- (void)initConfiguration {
    NSString *themeName = [UnityTool getStringValueForKey:USER_themName];
    if (themeName.length) {
        [ThemeManager shareInstance].themeStyle = [self returnThemeStyleWithThemeName:themeName];
        [ThemeManager shareInstance].tabarClor = kCOLOR_RGBValue(0xf1c40f);
        [FontManager shareInstance].fontColorStyle = [self returnFontColorStyleWithThemeName:themeName];
        [FontManager shareInstance].fontStyle = kFontStyleGillSans;
    } else {
        [ThemeManager shareInstance].themeStyle = kThemeStyleGray;
        [ThemeManager shareInstance].tabarClor = kCOLOR_RGBValue(0xf1c40f);
        [FontManager shareInstance].fontColorStyle = kThemeStyleGray;
        [FontManager shareInstance].fontStyle = kFontStyleGillSans;
    }
}

- (kThemeStyle)returnThemeStyleWithThemeName:(NSString *)themeName {
    if ([themeName isEqualToString:@"redTheme"]) {
        return kThemeStyleRed;
    } else if ([themeName isEqualToString:@"orangeTheme"]) {
        return kThemeStyleOrange;
    } else {
        return kThemeStyleGray;
    }
}

- (kFontColorStyle)returnFontColorStyleWithThemeName:(NSString *)themeName {
    if ([themeName isEqualToString:@"redTheme"]) {
        return kFontColorStyleRed;
    } else if ([themeName isEqualToString:@"orangeTheme"]) {
        return kFontColorStyleOrange;
    } else {
        return kFontColorStyleGray;
    }
}


#pragma mark - Setter

- (void)setThemeStyle:(kThemeStyle)themeStyle {
    _themeStyle = themeStyle;
    switch (themeStyle) {
        case kThemeStyleRed:{
            self.mainColor = KCOLOR(250,89,41);
            [UnityTool setStringValue:@"redTheme" forKey:USER_themName];
        }
            break;
        case kThemeStyleOrange:{
            self.mainColor = kCOLOR_RGBValue(0xfc9154);
            [UnityTool setStringValue:@"orangeTheme" forKey:USER_themName];
        }
            break;
        case kThemeStyleGray:{
            self.mainColor = kCOLOR_RGBValue(0x333333);
            [UnityTool setStringValue:@"grayTheme" forKey:USER_themName];
        }
            break;
        default:
            break;
    }
}

- (void)setMainColor:(UIColor *)mainColor {
    _mainColor = mainColor;
}

- (void)setTabarClor:(UIColor *)tabarClor {
    _tabarClor = tabarClor;
}

@end
